/*------------------------------------------------------------------------------
$module:      lockers
$package:     CseApi
$purpose:     unix/linux implement for locker
$author:      WAYNE WORK STDIO
$CreateAt:    10/05/20
$LastModify:
$license:     Mozilla Public License Version 1.1
------------------------------------------------------------------------------*/

#include "CseApi/platform.h"
#include "CseApi/lockers.h"

TCriticalSection::TCriticalSection()
{
    pthread_mutexattr_t m_attr;
    pthread_mutexattr_init(&m_attr);
    pthread_mutexattr_settype(&m_attr,PTHREAD_MUTEX_RECURSIVE);

    pthread_mutex_init(&m_critical,&m_attr);
}

TCriticalSection::~TCriticalSection()
{
    pthread_mutex_destroy(&m_critical);
}

void TCriticalSection::enter()
{
    pthread_mutex_lock(&m_critical);
}

void TCriticalSection::leave()
{
    pthread_mutex_unlock(&m_critical);
}
